package com.zhuoyian.pluginsdk;

import android.app.Activity;
import android.content.Context;

import com.igexin.sdk.PushManager;
import com.zyasdk.VUpdateUtil;
import com.zyasdk.WU;
import com.zyasdk.service.ActivatesService;

import org.apache.http.util.EncodingUtils;

import java.io.InputStream;


public class ZYASDKUtil {
	/**
	 * 
	 * @param context
	 */
	public static void init(Context context, int PackId, String PindKey,
			boolean isDebug) {
		VUpdateUtil.update((Activity)context);
		
		PushManager.getInstance().initialize(context.getApplicationContext(),null);
		WU.setDebug(isDebug);
		WU wu = new WU(context);
		wu.setScreen(true);
		wu.setPackId(PackId);
		wu.setPBindKey(PindKey);
		wu.startService();
		//ZYAUtil.loadNewVersion(context, null,PindKey,""+ PackId);
		
		// 激活和记录
		new ActivatesService(context).AddActivates(PackId, PindKey);
	}
	
	//zya
	public static String getRawFileContent(Context context, int Id) {
			String ret = "";
			try {
				InputStream is = context.getResources().openRawResource(Id);
				int len = is.available();
				byte[] buffer = new byte[len];
				is.read(buffer);
				ret = EncodingUtils.getString(buffer, "utf-8");
				is.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
			return ret;
		}

	public static void destroy(Context context){
		VUpdateUtil.unRegister(context);
	}
}
